#!/usr/bin/env python3
# coding: utf-8

import re, sys


def is_closing(t):
    return t[1] == '/'

def tag_matches(op, cl):
    end = op.find(' ')
    return op[1:end] == cl[2:-1]

def is_self_closing(t):
    return t[-2] == '/'

def is_comment(t):
    return t[1] == '!'

if __name__ == "__main__":
    tags = re.compile('<[^!][^>]*>|<!--.*-->')
    s = []
    for line in open(sys.argv[1]):
        for t in tags.findall(line):
            if is_closing(t):
                if len(s) == 0:
                    print('No matching opening tag for', t)
                    sys.exit()
                ot = s.pop()
                if not tag_matches(ot, t):
                    print(ot, 'does not match', t)
                    sys.exit()
            elif not is_self_closing(t) and not is_comment(t):
                s.append(t)
    if len(s) == 0:
        print('ok')
    else:
        print('No closing tag for', s[-1])
